using Ec.NETCoreFramework.Common.Core.Helpers;
using Ec.NETCoreFramework.Common.Core.Serializer;
using Ec.NETCoreFramework.Common.Plug.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQ_WechatCustomContact;
using MQ_WechatMedia;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace UnitTest
{
    [TestClass]
    public class UnitWechat
    {
        public AppConfig _AppConfig = null;
        private ConsumeConfig _ConsumeConfig;
        [TestInitialize]
        public void Init()
        {
            var appConfig = (new ConfigHelper().Get<AppConfig>("appconfig", "Development") ?? new AppConfig());

            _ConsumeConfig = appConfig.Jobs[0].Consumes[0];
            _ConsumeConfig.AppId = appConfig.ReqAppSecret.AppId;
            _ConsumeConfig.Secret = appConfig.ReqAppSecret.Secret;

        }
        [TestMethod]
        public void MediaTest()
        {

            //Job_WechatMedia.Media media = new Job_WechatMedia.Media();
            //media.InitJobModel();

            Media media = new Media();
            media.SetConsumeConfig(ProtoBufSerializer.Serializeby(_ConsumeConfig));
            var msg = "hello";
            Task t = media.ConsumeEvent(Encoding.UTF8.GetBytes(msg));
            t.Wait();


        }
        [TestMethod]
        public void MobileToUser()
        {
            CustomContact mobile = new CustomContact();
            mobile.SetConsumeConfig(ProtoBufSerializer.Serializeby(_ConsumeConfig));
            var dic = new Dictionary<string, object>()
            {
                {"fk_id","1071" },
                {"db_id","53" },
                {"action","MobileToUser" },
                //{"action","ExternalContact" },
            };
            var msg = ByteSerializer.Serialize(dic);
            Task t = mobile.ConsumeEvent(msg);
            t.Wait();

        }
        [TestMethod]
        public void GroupChatTest()
        {
            CustomContact mobile = new CustomContact();
            mobile.SetConsumeConfig(ProtoBufSerializer.Serializeby(_ConsumeConfig));
            var dic = new Dictionary<string, object>()
            {
                {"fk_id","901" },
                {"db_id","53" },
                {"action","GroupChat" }
            };
            var msg = ByteSerializer.Serialize(dic);
            Task t = mobile.ConsumeEvent(msg);
            t.Wait();
        }
    }
}
